#include "Config.h"
#include "DBConfig.h"
#include "DBStream.h"

// ----------------------------------- FileHelper ----------------------------------------

namespace db
{

bool FileHelper::write_wstring(WriteStream& file, const std::wstring& data)
{
    const SizeType size = data.size();
    if (!file.write(&size, sizeof(size))) return false;
    file.write(data.c_str(), size * sizeof(wchar_t));
    return true;
}

bool FileHelper::read_wstring(ReadStream& file, std::wstring& data)
{
    SizeType size;
    file.read(&size, sizeof(size));

    wchar_t *d = new wchar_t[size + 1];
    file.read(d, size * sizeof(wchar_t));
    d[size] = '\0';
    data = d;
    delete[] d;

    return true;
}

};